package tests.update;

import static org.junit.Assert.*;

import java.util.ArrayList;

import model.Budget;
import model.BudgetFactory;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.workplicity.util.Helper;
import org.workplicity.worklet.WorkletContext;

import com.mongodb.BasicDBObject;
import com.mongodb.util.JSON;

public class BudgetUpdateNameTest00
{

	Budget budget;
	BudgetFactory factory;

	@Before
	public void setUp() throws Exception
	{
		factory = new BudgetFactory();
		budget = (Budget) factory.create();
        budget.setName("Test budget");
        budget.setDescription("This is an update test budget.");
        budget.commit();
        
        budget.setName("New Budget");
        budget.commit();
	}

	@After
	public void tearDown() throws Exception
	{
		Helper.delete(budget, WorkletContext.getInstance());
	}

	@SuppressWarnings("unchecked")
	@Test
	public void test()
	{
		BasicDBObject pred = new BasicDBObject("budget.name", "Test budget");
		String criteria = JSON.serialize(pred);
		ArrayList<Budget> budgets = Helper.query(criteria, WorkletContext.getInstance());
		try{
			if(budgets.size() != 0);
				fail("Querying by false name passed unexpectedly");
		}
		catch (Exception e){
			fail("Fetching budget by false name failed with exception " + e);
		}
	}


}
